package batch.home;

import javax.xml.parsers.*;

import org.xml.sax.*;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import java.util.Date;
import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.*;

import java.util.Vector;
import java.util.Properties;
import java.io.*;
import java.net.*;

import java.sql.*;
import java.io.*;
import java.net.URL;
import batch.common.db.ConnectionManager;

public class makeAstoreHtmlGer4 {
	
	final String strJavaName = "A.Store Gbr";
    final int    ILENG       = 1;

    private final String TODAY              = DateFormatUtils.format(new Date(), "yyyyMMdd");  //Get Current Date
    private final String MAILSUBJECT        = "CP Html Batch Error(" + TODAY + ")";
    private final String FILE_PATH          = "/home02/nas/ger_pub/sm3/astore/";
    private final String ROOT_URL    = "http://uk.samsungmobile.com";
    private final String APP_URL = "http://de-ms.samsungapps.com/sfcApplicationList.as";

    String strContentName = "";
    String strPreviewUrl = "";
    String strContentID = "";
    String strUrl = "";
    
    String content_id = "";
    String content_name = "";
    String order_url = "";
    String content_link = "";
    String content_price = "";
    String more_link = "";
   
    String title		 = "";
    String alt_title	 = "";
    String category		 = "";
    String preview_url	 = "";
    String seller_name	 = "";
    String rating		 = "";
    String price		 = "";
    String currency_unit = "";
    String icon_flag	 = "";
    String detail_url	 = "";    
    
    String fileName = "";    
    
    String Phone_model = "";    
    String CP_URL = "http://funclub.tr.samsungmobile.com/xml/xml.jsp?NUM=5&MODEL=";
    
    private StringBuffer sHtml = new StringBuffer();

    public makeAstoreHtmlGer4(){
    	Homeinit();
    	Productinit();
    }
    public void Homeinit(){
        BufferedReader bfrString = null;
        StringBuffer sbfXml = new StringBuffer();

        Document doc = null;
        NodeList nlTemp = null;
        NodeList nlTemp2 = null;
        NodeList nlTemp3 = null;        
    	
        OutputStreamWriter fw = null;
        
        try{
				URLConnection urlCon = new URL(APP_URL+"?NUM=15&REQUEST_ID=01&MODEL=&LANG=&").openConnection();
				bfrString = new BufferedReader(new InputStreamReader(urlCon.getInputStream(), "ISO-8859-1"));
							
	            String line = "";
	            Vector vtElem        = new Vector();
	            Vector vAstore        = new Vector();
	            Vector vTmpMore		 = new Vector();

	            while ((line = bfrString.readLine()) != null)
	            {
	                sbfXml.append(line);
	            }

	            byte bxml[] = sbfXml.toString().getBytes("ISO-8859-1");
	            ByteArrayInputStream is = new ByteArrayInputStream(bxml);

	            DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
	            DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
	            doc = docBuilder.parse(new InputSource(is));
	            Element elem = doc.getDocumentElement();
	            elem.normalize();

	            nlTemp = elem.getChildNodes();
	  
	                for(int x=0;x<nlTemp.getLength();x++){
	                    if(nlTemp.item(x).getChildNodes().getLength() > 0){
	                        vtElem.addElement(nlTemp.item(x).getChildNodes());
	                    }
	                }
	                
	                for(int x=0;x<vtElem.size();x++){
	                    Element tmpElem = (Element)vtElem.elementAt(x);
	                    String strElem = tmpElem.getTagName();
	                    
						if(strElem.equals("return")){	                    
		                    String return_tmp = tmpElem.getFirstChild().getNodeValue();                        
						}
	
						if(strElem.equals("total_count")){	                    
		                    String total_count = tmpElem.getFirstChild().getNodeValue();                        
						}					
						
	                    //vTmpMore.add(more_tmp); // More Link 

						if(strElem.equals("application")){
		                    for (int i = 0; i < ILENG; i++) {
		                        Properties pptNode = new Properties();
		                        
		                        nlTemp = tmpElem.getElementsByTagName("title");
		                        pptNode.setProperty("title", nlTemp.item(i).getFirstChild().getNodeValue());
		                        nlTemp = tmpElem.getElementsByTagName("category");
		                        pptNode.setProperty("category", nlTemp.item(i).getFirstChild().getNodeValue());
		                        nlTemp = tmpElem.getElementsByTagName("preview_url");
		                        pptNode.setProperty("preview_url", nlTemp.item(i).getFirstChild().getNodeValue());
		                        nlTemp = tmpElem.getElementsByTagName("seller_name");
		                        pptNode.setProperty("seller_name", nlTemp.item(i).getFirstChild().getNodeValue());
		                        nlTemp = tmpElem.getElementsByTagName("rating");
		                        pptNode.setProperty("rating", nlTemp.item(i).getFirstChild().getNodeValue());                        
		                        nlTemp = tmpElem.getElementsByTagName("price");
		                        pptNode.setProperty("price", nlTemp.item(i).getFirstChild().getNodeValue());
		                        nlTemp = tmpElem.getElementsByTagName("currency_unit");
		                        pptNode.setProperty("currency_unit", nlTemp.item(i).getFirstChild().getNodeValue());
		                        
		                        nlTemp = tmpElem.getElementsByTagName("icon_flag");
		                        if(nlTemp.item(i).getFirstChild()!=null){
		                        	pptNode.setProperty("icon_flag", nlTemp.item(i).getFirstChild().getNodeValue());
		                        } else {
		                        	pptNode.setProperty("icon_flag", "");		                        	
		                        }
		                        
		                        nlTemp = tmpElem.getElementsByTagName("detail_url");
		                        pptNode.setProperty("detail_url", nlTemp.item(i).getFirstChild().getNodeValue());	                        
		                        
		                        //pptNode.setProperty("more_link", more_tmp);
		                        
	                            vAstore.addElement(pptNode);
	
		                  }
		             }
	             }	
	
	            File fl = new File(FILE_PATH);
	
	            if(!fl.isDirectory()){
	                fl.mkdirs();
	            }
	
	            if(vAstore.size() > 0){
	            	getGameHomeMain(vAstore,vTmpMore);
	            	getProductRightHtml(vAstore,vTmpMore);
	            	getDownloadHtml(vAstore,vTmpMore);
	            }
        }catch(Exception ex){
            ex.printStackTrace();
            Logger.getLogger("home.tur_home").info(ex.toString());
            //ReportError.byEmail(MAILSUBJECT, ex.toString());
        }finally {
            if(bfrString != null) try { bfrString.close(); } catch (Exception e) {}
        }
    }
    
    public void Productinit(){
    	BufferedReader bfrString = null;

        String musicToneHtml = "";
        String GameHtml = "";
        String chek_flg = "";
        String phoneXml_url = APP_URL+"?NUM=15&REQUEST_ID=01&MODEL=";
    	
        StringBuffer sQuery = new StringBuffer();
        sQuery.append(" SELECT GSP.PHONE_MODEL                                                            \n")
	      .append(" FROM G_SFC_PRODUCT GSP ,G_SFC_PRD_BASE_IMAGE GSPBI,G_SFC_PHONE_CONTENT_ICON GSPCI ,G_SFC_CONTENT_ICON GSCI        \n")
	      .append(" WHERE GSP.DISPLAY_FLAG = 'Y' AND GSP.PHONE_MODEL = GSPBI.PHONE_MODEL (+) AND GSP.SITE_CD = GSPBI.SITE_CD (+) AND GSP.LANG_CD = GSPBI.LANG_CD (+) \n")
	      .append(" AND GSP.PHONE_MODEL = GSPCI.PHONE_MODEL  AND GSP.SITE_CD = GSPCI.SITE_CD  AND GSP.LANG_CD = GSPCI.LANG_CD      \n")
	      .append(" AND GSPCI.ICON_NO = GSCI.ICON_NO AND GSPCI.SITE_CD = GSCI.SITE_CD AND GSPCI.LANG_CD = GSCI.LANG_CD          \n")
	      .append(" AND GSCI.SITE_CD = 'gbr'  AND GSCI.LANG_CD = 'GER' AND GSCI.ICON_NO = '1'  AND GSCI.ASSIGN='Y'            \n");

        
        Connection conn   = null;
        Statement  stmt   = null;
        ResultSet  rs     = null;
        OutputStreamWriter fw = null;
        
        try{

        	conn = ConnectionManager.getConnection();
            conn.setAutoCommit(true);
            stmt= conn.createStatement();
            rs = stmt.executeQuery(sQuery.toString());
            while (rs.next()) {
            	
            	StringBuffer sbfXml = null;
                bfrString = null;
                sbfXml = new StringBuffer();

                Document doc = null;
                NodeList nlTemp = null;            	
                NodeList nlTemp2 = null;
                
            	ByteArrayInputStream is = null;
            	URLConnection urlCon = null;
            	
            	Phone_model   = ObjectUtils.toString(rs.getObject(1));
            	            	
            	System.out.println("phoneXml_url=========="+phoneXml_url+Phone_model);            	

	            urlCon = new URL(phoneXml_url+Phone_model+"&LANG=&").openConnection();
	            bfrString = new BufferedReader(new InputStreamReader(urlCon.getInputStream(), "ISO-8859-1"));
	            

				/*
	            fileName = FILE_PATH+"response.xml";

                if(!(new File(fileName)).exists()){
                    System.out.println("NO File..!!");
                }				
                bfrString = new BufferedReader(new InputStreamReader(new FileInputStream(fileName), "ISO-8859-1"));
                */
	            
	
	            String line = "";
	            Vector vtElem        = new Vector();
	            Vector vStorePhoneDetail     = new Vector();
	
	            while ((line = bfrString.readLine()) != null)
	            {
	                sbfXml.append(line);
	            }
	            
	            byte bxml[] = sbfXml.toString().getBytes("ISO-8859-1");
	            
	            is = new ByteArrayInputStream(bxml);
	
	            DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
	            DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
	            
	            doc = docBuilder.parse(new InputSource(is));
	            Element elem = doc.getDocumentElement();
	            elem.normalize();
	
	            nlTemp = elem.getChildNodes();
	            
	                for(int x=0;x<nlTemp.getLength();x++){
	                    if(nlTemp.item(x).getChildNodes().getLength() > 0){
	                        vtElem.addElement(nlTemp.item(x).getChildNodes());
	                    }
	                }
	                
	                for(int x=0;x<vtElem.size();x++){
	                    Element tmpElem = (Element)vtElem.elementAt(x);
	                    String strElem = tmpElem.getTagName();

						if(strElem.equals("return")){	                    
		                    String return_tmp = tmpElem.getFirstChild().getNodeValue();                        
						}
	
						if(strElem.equals("total_count")){	                    
		                    String total_count = tmpElem.getFirstChild().getNodeValue();                        
						}					
	                    
						if(strElem.equals("application")){
							chek_flg = "ok";
		                    for (int i = 0; i < ILENG; i++) {
		                        Properties pptNode = new Properties();
		                        
		                        nlTemp = tmpElem.getElementsByTagName("title");
		                        pptNode.setProperty("title", nlTemp.item(i).getFirstChild().getNodeValue());
		                        nlTemp = tmpElem.getElementsByTagName("category");
		                        pptNode.setProperty("category", nlTemp.item(i).getFirstChild().getNodeValue());
		                        nlTemp = tmpElem.getElementsByTagName("preview_url");
		                        pptNode.setProperty("preview_url", nlTemp.item(i).getFirstChild().getNodeValue());
		                        nlTemp = tmpElem.getElementsByTagName("seller_name");
		                        pptNode.setProperty("seller_name", nlTemp.item(i).getFirstChild().getNodeValue());
		                        nlTemp = tmpElem.getElementsByTagName("rating");
		                        pptNode.setProperty("rating", nlTemp.item(i).getFirstChild().getNodeValue());                        
		                        nlTemp = tmpElem.getElementsByTagName("price");
		                        pptNode.setProperty("price", nlTemp.item(i).getFirstChild().getNodeValue());
		                        nlTemp = tmpElem.getElementsByTagName("currency_unit");
		                        pptNode.setProperty("currency_unit", nlTemp.item(i).getFirstChild().getNodeValue());
		                        
		                        nlTemp = tmpElem.getElementsByTagName("icon_flag");
		                        if(nlTemp.item(i).getFirstChild()!=null){
		                        	pptNode.setProperty("icon_flag", nlTemp.item(i).getFirstChild().getNodeValue());
		                        } else {
		                        	pptNode.setProperty("icon_flag", "");		                        	
		                        }
		                        
		                        nlTemp = tmpElem.getElementsByTagName("detail_url");
		                        pptNode.setProperty("detail_url", nlTemp.item(i).getFirstChild().getNodeValue());	                        
		                        
		                        //pptNode.setProperty("more_link", more_tmp);
		                        
		                        vStorePhoneDetail.addElement(pptNode);
	
		                  }
		             }	                
	                
	                
	                }
	
	            File fl = new File(FILE_PATH);
	
	            if(!fl.isDirectory()){
	                fl.mkdirs();
	            }

	            if(vStorePhoneDetail.size() > 0){
	            	musicToneHtml = getApplicationDetail(vStorePhoneDetail,Phone_model);
	            }	            
	            
	            if(chek_flg.equals("ok")){
		            fw = new OutputStreamWriter(new FileOutputStream(FILE_PATH+ "/"+"astore_"+Phone_model+".html",false), "utf-8");
		            fw.write(musicToneHtml);
		            fw.close();
		            chek_flg = "";
	            }   

            } //while End
	            
        }catch(Exception ex){
            ex.printStackTrace();
            Logger.getLogger("home.tur_home").info(ex.toString());
            //ReportError.byEmail(MAILSUBJECT, ex.toString());
        }finally {
            if(bfrString != null) try { bfrString.close(); } catch (Exception e) {}
            if (fw != null) try { fw.close(); } catch (Exception e) {}
            if(rs        != null) try { rs.close();        } catch(Exception se) {}
            if(stmt      != null) try { stmt.close();      } catch(Exception se) {}
            if(conn      != null) try { conn.close();      } catch(Exception se) {}            
        }
    }
    
    
    public String getApplicationDetail(Vector pVector, String Phone_model) throws Exception {

        String htmlCpAll = "";
        
        float rating_tmp;
        String rating_img = "";

        try{
            sHtml.setLength(0);
            
            if(pVector.size() > 0) {
            	for(int i=0; i<pVector.size(); i++){
	                Properties pContentList = (Properties) pVector.elementAt(i);
	                alt_title = StringUtils.defaultString(pContentList.getProperty("title"),"");
	                category = StringUtils.defaultString(pContentList.getProperty("category"),"");
	                preview_url = StringUtils.defaultString(pContentList.getProperty("preview_url"),"");
	                seller_name = StringUtils.defaultString(pContentList.getProperty("seller_name"),"");
	                rating = StringUtils.defaultString(pContentList.getProperty("rating"),"0");
	                price = StringUtils.defaultString(pContentList.getProperty("price"),"");            
	                currency_unit = StringUtils.defaultString(pContentList.getProperty("currency_unit"),"");
	                icon_flag = StringUtils.defaultString(pContentList.getProperty("icon_flag"),"");
	                detail_url = StringUtils.defaultString(pContentList.getProperty("detail_url"),"");	                
	                	                
	                if(alt_title.length() > 46){
	                	title = alt_title.substring(0, 45) + "..";
	                }else{
	                	title = alt_title;
	                }
	                
	                rating_tmp = new Float(rating).floatValue();
	                
	                if(rating_tmp == 0.5) rating_img ="<img src=/image/products/star_half.gif align=middle><img src=/image/products/star_empty.gif align=middle><img src=/image/products/star_empty.gif align=middle><img src=/image/products/star_empty.gif align=middle><img src=/image/products/star_empty.gif align=middle>\n";	                
	                else if(rating_tmp == 1) rating_img ="<img src=/image/products/star_full.gif align=middle><img src=/image/products/star_empty.gif align=middle><img src=/image/products/star_empty.gif align=middle><img src=/image/products/star_empty.gif align=middle><img src=/image/products/star_empty.gif align=middle>\n";	                
	                else if(rating_tmp == 1.5) rating_img ="<img src=/image/products/star_full.gif align=middle><img src=/image/products/star_half.gif align=middle><img src=/image/products/star_empty.gif align=middle><img src=/image/products/star_empty.gif align=middle><img src=/image/products/star_empty.gif align=middle>\n";
	                else if(rating_tmp == 2) rating_img ="<img src=/image/products/star_full.gif align=middle><img src=/image/products/star_full.gif align=middle><img src=/image/products/star_empty.gif align=middle><img src=/image/products/star_empty.gif align=middle><img src=/image/products/star_empty.gif align=middle>\n";
	                else if(rating_tmp == 2.5) rating_img ="<img src=/image/products/star_full.gif align=middle><img src=/image/products/star_full.gif align=middle><img src=/image/products/star_half.gif align=middle><img src=/image/products/star_empty.gif align=middle><img src=/image/products/star_empty.gif align=middle>\n";
	                else if(rating_tmp == 3) rating_img ="<img src=/image/products/star_full.gif align=middle><img src=/image/products/star_full.gif align=middle><img src=/image/products/star_full.gif align=middle><img src=/image/products/star_empty.gif align=middle><img src=/image/products/star_empty.gif align=middle>\n";
	                else if(rating_tmp == 3.5) rating_img ="<img src=/image/products/star_full.gif align=middle><img src=/image/products/star_full.gif align=middle><img src=/image/products/star_full.gif align=middle><img src=/image/products/star_half.gif align=middle><img src=/image/products/star_empty.gif align=middle>\n";
	                else if(rating_tmp == 4) rating_img ="<img src=/image/products/star_full.gif align=middle><img src=/image/products/star_full.gif align=middle><img src=/image/products/star_full.gif align=middle><img src=/image/products/star_full.gif align=middle><img src=/image/products/star_empty.gif align=middle>\n";
	                else if(rating_tmp == 4.5) rating_img ="<img src=/image/products/star_full.gif align=middle><img src=/image/products/star_full.gif align=middle><img src=/image/products/star_full.gif align=middle><img src=/image/products/star_full.gif align=middle><img src=/image/products/star_half.gif align=middle>\n";
	                else if(rating_tmp > 4.5) rating_img ="<img src=/image/products/star_full.gif align=middle><img src=/image/products/star_full.gif align=middle><img src=/image/products/star_full.gif align=middle><img src=/image/products/star_full.gif align=middle><img src=/image/products/star_full.gif align=middle>\n";
	                else rating_img ="<img src=/image/products/star_empty.gif align=middle><img src=/image/products/star_empty.gif align=middle><img src=/image/products/star_empty.gif align=middle><img src=/image/products/star_empty.gif align=middle><img src=/image/products/star_empty.gif align=middle>\n";
	                
	                sHtml.append("<li>\n")
		            .append("<a target='_blank' href='" + this.detail_url + "'><img src='" + this.preview_url + "' width='77px' height='77px' class='thumb_img' alt='" + this.alt_title + "' title='" + this.alt_title + "' /></a> \n")
		            .append("<p class='tit'><a target='_blank' href='" + this.detail_url + "'>" + this.title + "</a></p> \n")
		            .append("<p class='cate'>" + this.category + "</p> \n")
		            .append("<p class='seller'><span>Seller :</span> " + this.seller_name + "</p> \n")
		            .append("<span class='ico'><a target='_blank' href='" + this.detail_url + "'><img src='/images/common/btn/ico_computer1_off.gif' onmouseover='ImageOver(this)' onmouseout='ImageOut(this)' alt='" + this.alt_title + "' title='" + this.alt_title + "' /></a></span> \n")
		            .append("</li> \n");             
	                
            	}
            	
            }
            
            htmlCpAll = sHtml.toString();

        }catch(Exception ex){
        	ex.printStackTrace();
        }
        return htmlCpAll;
    }    
    
    // FRONT MAIN HTML
    public void getGameHomeMain(Vector pVector, Vector vMore) throws Exception  {
        OutputStreamWriter fw = null;

        //String moreLink = "";
        //if (vMore != null || vMore.equals("")) moreLink = (String)vMore.elementAt(5);
        
        try{
            /* Front MAIN Page Game*/
            sHtml.setLength(0);
                        
            if(pVector.size() > 0) {
            	for(int i=0; i<pVector.size(); i++){
	                Properties pContentList = (Properties) pVector.elementAt(i);
	                alt_title = StringUtils.defaultString(pContentList.getProperty("title"),"");
	                category = StringUtils.defaultString(pContentList.getProperty("category"),"");
	                preview_url = StringUtils.defaultString(pContentList.getProperty("preview_url"),"");
	                seller_name = StringUtils.defaultString(pContentList.getProperty("seller_name"),"");
	                rating = StringUtils.defaultString(pContentList.getProperty("rating"),"");
	                price = StringUtils.defaultString(pContentList.getProperty("price"),"");            
	                currency_unit = StringUtils.defaultString(pContentList.getProperty("currency_unit"),"");
	                icon_flag = StringUtils.defaultString(pContentList.getProperty("icon_flag"),"");
	                detail_url = StringUtils.defaultString(pContentList.getProperty("detail_url"),"");	                

	                if(alt_title.length() > 46){
	                	title = alt_title.substring(0, 45) + "..";
	                }else{
	                	title = alt_title;
	                }	                
	                
	                sHtml.append("<li>\n")
		            .append("<a target='_blank' href='" + this.detail_url + "'><img src='" + this.preview_url + "' width='77px' height='77px' class='thumb_img' alt='" + this.alt_title + "' title='" + this.alt_title + "' /></a> \n")
		            .append("<p class='tit'><a target='_blank' href='" + this.detail_url + "'>" + this.title + "</a></p> \n")
		            .append("<p class='cate'>" + this.category + "</p> \n")
		            .append("<p class='seller'><span>Seller :</span> " + this.seller_name + "</p> \n")
		            .append("<span class='ico'><a target='_blank' href='" + this.detail_url + "'><img src='/images/common/btn/ico_computer1_off.gif' onmouseover='ImageOver(this)' onmouseout='ImageOut(this)' alt='" + this.alt_title + "' title='" + this.alt_title + "' /></a></span> \n")
		            .append("</li> \n"); 
            	}
            	
            }
           

            System.out.println("sHtml.toString()====="+sHtml.toString());            
            
            
            fw = new OutputStreamWriter(new FileOutputStream(FILE_PATH + "/astoreaMainHtml.html",false), "utf-8");
            fw.write(sHtml.toString());
            fw.close();

        }finally{
            if (fw != null) try { fw.close(); } catch (Exception e) {}
        }
    }    


    public void getProductRightHtml(Vector pVector, Vector vMore) throws Exception  {
        OutputStreamWriter fw = null;

        try{
            sHtml.setLength(0);
            
            
            sHtml.append("<dl class='mBox200 mt5'>\n")
            .append("	<dt>Applications for This phone</dt>\n")
            .append("	<dd class='dd_Community'>\n");


            if(pVector.size() > 0) {
            	for(int i=0; i<2; i++){
	                Properties pContentList = (Properties) pVector.elementAt(i);
	                title = StringUtils.defaultString(pContentList.getProperty("title"),"");
	                category = StringUtils.defaultString(pContentList.getProperty("category"),"");
	                preview_url = StringUtils.defaultString(pContentList.getProperty("preview_url"),"");
	                seller_name = StringUtils.defaultString(pContentList.getProperty("seller_name"),"");
	                rating = StringUtils.defaultString(pContentList.getProperty("rating"),"");
	                price = StringUtils.defaultString(pContentList.getProperty("price"),"");            
	                currency_unit = StringUtils.defaultString(pContentList.getProperty("currency_unit"),"");
	                icon_flag = StringUtils.defaultString(pContentList.getProperty("icon_flag"),"");
	                detail_url = StringUtils.defaultString(pContentList.getProperty("detail_url"),"");	                

	                if(title.length() > 13){
	                	title = title.substring(0, 12) + "..";
	                }	                
	                
	                sHtml.append("		<div class='prdInfo pb5'>\n")
	                .append("			<div class='imgBox50'>\n")
	                .append("				<a href='"+detail_url+"'><img src='"+preview_url+"' alt='"+title+"' width='50' height='50'></a>\n")
	                .append("			</div>\n")
	                .append("			<div class='list'>\n")
	                .append("				<p class='p_tit'><a href='"+detail_url+"'>"+title+"</a></p>\n")
	                .append("				<p class='p_detail'>\n")
	                .append("					<span class='t_dBlue'>"+category+"</span><br>\n")
	                .append("					<span><a href='"+detail_url+"'><img src='/image/common/btn_detail.gif' alt='Detail'></a></span>\n")
	                .append("				</p>\n")
	                .append("			</div>\n")
	                .append("		</div>\n");
            	}
            	
            }

            sHtml.append("	</dd>\n")
            .append("</dl>\n");            
            
            fw = new OutputStreamWriter(new FileOutputStream(FILE_PATH + "/productRight_html.html",false), "utf-8");
            fw.write(sHtml.toString());
            fw.close();

        }finally{
            if (fw != null) try { fw.close(); } catch (Exception e) {}
        }
    }    
    
    public void getDownloadHtml(Vector pVector, Vector vMore) throws Exception  {
        OutputStreamWriter fw = null;
        
        try{
            /* Front MAIN Page Game*/
            sHtml.setLength(0);

            sHtml.append("		<dl class='mboxG2'>\n")
            .append("			<dt>Top Applications</dt>\n")
            .append("			<a href='http://www.appket.com' class='more' title='Samsung mobile games top 5' target='_blank'>more</a>\n")
            .append("			<dd class='TopApp'>\n")
            .append("			<ul>\n");
            
            if(pVector.size() > 0) {
            	for(int i=0; i<6; i++){
	                Properties pContentList = (Properties) pVector.elementAt(i);
	                title = StringUtils.defaultString(pContentList.getProperty("title"),"");
	                category = StringUtils.defaultString(pContentList.getProperty("category"),"");
	                preview_url = StringUtils.defaultString(pContentList.getProperty("preview_url"),"");
	                seller_name = StringUtils.defaultString(pContentList.getProperty("seller_name"),"");
	                rating = StringUtils.defaultString(pContentList.getProperty("rating"),"");
	                price = StringUtils.defaultString(pContentList.getProperty("price"),"");            
	                currency_unit = StringUtils.defaultString(pContentList.getProperty("currency_unit"),"");
	                icon_flag = StringUtils.defaultString(pContentList.getProperty("icon_flag"),"");
	                detail_url = StringUtils.defaultString(pContentList.getProperty("detail_url"),"");	                
	                
	                if(title.trim().length() > 13){
	                	title = title.substring(0, 12) + "..";
	                }	                
	                
	                sHtml.append("				<li>\n")
	                .append("					<div class='imgBox77'>\n")
	                .append("						<img src='"+preview_url+"' alt='"+title+"' title='"+title+"' width='77' height='77'>\n")
	                .append("					</div>\n")
	                .append("					<p class='p_tit'>\n")
	                .append("						<a href='"+detail_url+"'>"+title+"</a>\n")
	                .append("					</p>\n")
	                .append("					<a href='"+detail_url+"'><img src='/image/common/btn_detail.gif' alt='Detail'></a>\n")
	                .append("					<img src='/image/products/btn_free.gif' alt='Free'>\n")
	                .append("				</li>\n");
            	}
            	
            }

            sHtml.append("			</ul>\n")
            .append("			</dd>\n")
            .append("		</dl>\n");
            
            fw = new OutputStreamWriter(new FileOutputStream(FILE_PATH + "/downLoadAppHtml.html",false), "utf-8");
            fw.write(sHtml.toString());
            fw.close();

        }finally{
            if (fw != null) try { fw.close(); } catch (Exception e) {}
        }
    }    
    
    
    
    public static void main( String[] args ){
      Logger.getLogger("home.tur_home").info("( * ) Start.");
      makeAstoreHtmlGer4 mvm = new makeAstoreHtmlGer4();
      Logger.getLogger("home.tur_home").info("( * ) End.");
    }
}

